var _util = require('util/util.js');
var _order_service = require('service/order-service.js');
var listTemplate = require('./index.string');

require('page/common/header/index.js');

var myOrders = {
    listDate : {
        itemList    : {}
    },
    init: function () {
        this.bindEvents();
        this.loadAccountInfo();
        return this;
    },
    bindEvents: function () {
        $('#return_menu').click (
            function () {
                window.location.href = './catalog-main.html';
            }
        )
    },
    loadAccountInfo : function(){
        var id = _util.getURLParam('id');
        var route = _util.getURLParam('route');
        var _this = this;
        console.log("id"+id);
        console.log("route"+route);
        if(id === 'toMyAccount'){
            _order_service.myOders(
                route,
                function(res){
                    _this.listDate.itemList = res;

                    var result = _util.renderHtml(listTemplate, {ListData : _this.listDate});
                    $('#orders').html(result);
                },
                function(errMsg) {
                    console.log('errMsg...'+errMsg);

                }
            );
        }
    }
}
module.exports = myOrders.init();